package com.qersoft.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.databind.util.BeanUtil;
import com.qersoft.entity.Dictionary;
import com.qersoft.service.DictionaryService;
import com.qersoft.vo.DictionaryVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/training/dictionary")
public class DicconTroller {

    @Autowired
    private DictionaryService dictionaryService;

    @PostMapping("add")
    public String add(@RequestBody Dictionary dictionary) {
        Integer i= dictionaryService.add(dictionary);
        if(i>0){
            return "success";
        }
        else {
            return "fail";
        }
    }

    @GetMapping("list")
    public IPage<Dictionary> list(@RequestBody DictionaryVo vo) {

        Dictionary dictionary = new Dictionary();
        BeanUtils.copyProperties(vo,dictionary);

        return dictionaryService.list(dictionary, vo.getCurpage(), vo.getLimit());

    }
}
